﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;


namespace StudentManagerPro
{
    public partial class FrmModifyPwd : Form
    {
        public FrmModifyPwd()
        {
            InitializeComponent();
        }
        //修改密码
        private void btnModify_Click(object sender, EventArgs e)
        {
            // 1: 验证：新密码和新密码确认是否一致、是否都满足正则
            string parttem = @"^\d{3,8}$";
            if (!Regex.IsMatch(txtNewPwd.Text, parttem) || !Regex.IsMatch(txtNewPwdConfirm.Text, parttem) || !Regex.IsMatch(txtOldPwd.Text, parttem))
            {
                MessageBox.Show("输入密码不合法，请输入3—8为的数字");
                return;
            }
            if (txtNewPwd.Text != txtNewPwdConfirm.Text)
            {
                MessageBox.Show("新密码与确认密码不一致");
                return;
            }
            // 2: 验证： 原密是否正确
            if (txtOldPwd.Text != Common.Global.Password)
            {
                MessageBox.Show("原始密码错误");
                return;
            }
            // 3: 都对了，根据当前登录用户，更新字段。
            Console.WriteLine("都对了，修改密码了");
            string msg = DAL.LoginServe.MotifyPwd(txtNewPwd.Text);
            MessageBox.Show(msg);
            if(msg== "更新失败")
            {

                txtOldPwd.Text = "";
                txtNewPwd.Text = "";
                txtNewPwdConfirm.Text = "";
            }
            else
            {
                this.Close();
            }
        }
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
